import random


class AddressDTO:
    def __init__(self):
        self.province = None
        self.city = None
        self.district = None
        self.address = None

    def set_province(self, province):
        self.province = province

    def set_city(self, city):
        self.city = city

    def set_district(self, district):
        self.district = district

    def set_address(self, address):
        self.address = address

    def get_province(self):
        return self.province

    def get_city(self):
        return self.city

    def get_district(self):
        return self.district

    def get_address(self):
        return self.address


class AddressGenerator:
    RANDOM = random.Random()

    # 简化的省、市数据
    PROVINCES_CITIES = {
        "广东省": ["深圳市", "广州市", "佛山市"],
        "湖北省": ["武汉市", "宜昌市", "襄阳市"],
        "湖南省": ["长沙市", "株洲市", "湘潭市"],
        "江苏省": ["南京市", "苏州市", "无锡市"],
        "浙江省": ["杭州市", "宁波市", "温州市"],
        "四川省": ["成都市", "绵阳市", "德阳市"],
        "河南省": ["郑州市", "洛阳市", "开封市"],
        "山东省": ["济南市", "青岛市", "淄博市"],
        "河北省": ["石家庄市", "唐山市", "秦皇岛市"],
        "山西省": ["太原市", "大同市", "阳泉市"]
    }

    # 简化的市、区数据
    CITIES_DISTRICTS = {
        "深圳市": ["宝安区", "南山区", "福田区", "罗湖区"],
        "广州市": ["天河区", "越秀区", "海珠区", "白云区"],
        "佛山市": ["禅城区", "南海区", "顺德区", "高明区"],
        "武汉市": ["武昌区", "江岸区", "江汉区", "硚口区"],
        "宜昌市": ["西陵区", "伍家岗区", "点军区", "猇亭区"],
        "襄阳市": ["樊城区", "襄城区", "高新区", "东津新区"],
        "长沙市": ["岳麓区", "芙蓉区", "天心区", "开福区"],
        "株洲市": ["天元区", "荷塘区", "石峰区", "芦淞区"],
        "湘潭市": ["雨湖区", "岳塘区", "湘乡市", "韶山市"],
        "南京市": ["玄武区", "秦淮区", "建邺区", "鼓楼区"],
        "苏州市": ["姑苏区", "吴中区", "相城区", "吴江区"],
        "无锡市": ["梁溪区", "滨湖区", "新吴区", "惠山区"],
        "杭州市": ["上城区", "下城区", "江干区", "滨江区"],
        "宁波市": ["海曙区", "江北区", "鄞州区", "镇海区"],
        "温州市": ["鹿城区", "龙湾区", "瓯海区", "瑞安县"],
        "成都市": ["锦江区", "青羊区", "金牛区", "武侯区"],
        "绵阳市": ["涪城区", "游仙区", "安州区", "江油市"],
        "德阳市": ["旌阳区", "罗江区", "广汉市", "什邡市"],
        "郑州市": ["中原区", "二七区", "金水区", "管城回族区"],
        "洛阳市": ["老城区", "西工区", "瀍河区", "涧西区"],
        "开封市": ["龙亭区", "顺河回族区", "鼓楼区", "禹王台区"],
        "济南市": ["历下区", "市中区", "槐荫区", "天桥区"],
        "青岛市": ["市南区", "市北区", "黄岛区", "崂山区"],
        "淄博市": ["张店区", "淄川区", "博山区", "周村区"],
        "石家庄市": ["长安区", "桥西区", "新华区", "裕华区"],
        "唐山市": ["路南区", "路北区", "古冶区", "开平区"],
        "秦皇岛市": ["海港区", "山海关区", "北戴河区", "抚宁区"],
        "太原市": ["小店区", "迎泽区", "杏花岭区", "尖草坪区"],
        "大同市": ["城区", "矿区", "南郊区", "新荣区"],
        "阳泉市": ["城区", "矿区", "郊区", "盂县"]
    }

    @staticmethod
    def generate_random_address():
        # 随机选择一个省
        province = AddressGenerator.get_random_key(AddressGenerator.PROVINCES_CITIES)
        # 根据省随机选择一个市
        city = AddressGenerator.get_random_element(AddressGenerator.PROVINCES_CITIES[province])
        # 根据市随机选择一个区
        district = AddressGenerator.get_random_element(AddressGenerator.CITIES_DISTRICTS[city])
        # 生成一个详细的地址
        detailed_address = AddressGenerator.generate_detailed_address()

        address = AddressDTO()
        address.set_province(province)
        address.set_city(city)
        address.set_district(district)
        address.set_address(detailed_address)

        return address

    @staticmethod
    def get_random_key(map_data):
        keys = list(map_data.keys())
        return keys[AddressGenerator.RANDOM.randint(0, len(keys) - 1)]

    @staticmethod
    def get_random_element(list_data):
        return list_data[AddressGenerator.RANDOM.randint(0, len(list_data) - 1)]

    @staticmethod
    def generate_detailed_address():
        streets = ["江岸路", "中山路", "人民路", "解放路", "建设路", "东风路", "红旗路", "幸福路", "友谊路", "光明路"]
        buildings = ["123号", "456号", "789号", "101号", "202号", "303号", "404号", "505号", "606号", "707号"]
        units = ["A座", "B座", "C座", "D座", "E座", "F座", "G座", "H座", "I座", "J座"]

        street = random.choice(streets)
        building = random.choice(buildings)
        unit = random.choice(units)

        return street + building + unit


if __name__ == "__main__":
    address = AddressGenerator.generate_random_address()
    print("省:", address.get_province())
    print("市:", address.get_city())
    print("区:", address.get_district())
    print("详细地址:", address.get_address())
